var t = require;
var e = module;
var o = exports;
var n =
    (this && this.__extends) ||
    (function () {
        var t = function (e, o) {
            return (t =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                })(e, o);
        };
        return function (e, o) {
            function n() {
                this.constructor = e;
            }
            t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
        };
    })();
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("fsm"),
    a = t("Util"),
    i = t("AIdelay"),
    s = t("AIIdle"),
    c = t("AISkill"),
    l = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (e.time = 0), (e.开始移动位置 = cc.v2()), e;
        }
        return (
            n(e, t),
            (e.prototype.onEnter = function () {
                (this.enemy = this.context.enemy.value),
                    "Run" != this.context.sk.getCur() && this.context.sk.play("Run", !0),
                    (this.开始移动位置.x = this.context.node.x),
                    (this.开始移动位置.y = this.context.node.y);
            }),
            (e.prototype.onExit = function () {
                this.context.stop();
            }),
            (e.prototype.onUpdate = function (t) {
                if (null != this.context.enemy.value) {
                    if (!this.context.enemy.value.isValid)
                        return (this.context.enemy.value = null), void r.changeState(this.context, s.default);
                    var e = this.context.skill.get_ready_skill();
                    if (
                        (e
                            ? e.is_Can_Attack_Enemy(this.context, this.context.enemy.value)
                                ? r.changeState(this.context, c.default, {skill: e})
                                : ((this.point = e.get_Best_attack_point(
                                      this.context,
                                      this.context.enemy.value,
                                      this.point
                                  )),
                                  this.moveto(this.point, t))
                            : r.changeState(this.context, i.default),
                        (this.time += t),
                        this.time >= 2 && ((this.time = 0), r.changeState(this.context, i.default)),
                        this.time >= 1)
                    ) {
                        var o = Math.abs(this.context.node.x - this.开始移动位置.x),
                            n = Math.abs(this.context.node.y - this.开始移动位置.y);
                        if (o <= 30 && n <= 30) {
                            var a = this.context.skill.get_random_pugong();
                            a && r.changeState(this.context, c.default, {skill: a});
                        }
                    }
                } else r.changeState(this.context, s.default);
            }),
            (e.prototype.moveto = function (t, e) {
                var o = t.x - this.context.node.x,
                    n = t.y - this.context.node.y,
                    r = a.Vector_to_unit_circle(o, n);
                this.context.moveTo(r.x, r.y);
            }),
            e
        );
    })(t("bodyAI").default);
o.default = l;
